<template>
  <div class="head-search">
    <el-form ref="searchFormRef" :inline="true" :label-width="labelWidth" :size="size" :model="modelValue"
      @submit.native.prevent>
      <slot></slot>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" :size="size" @click="search">查询</el-button>
        <el-button type="info" plain icon="el-icon-delete" :size="size" @click="resetForm(searchFormRef)">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script lang="ts">
export default { name: 'AutumnSearch' }
</script>

<script lang="ts" setup>
import { ref } from 'vue'
import type { FormInstance } from 'element-plus'

const searchFormRef = ref<FormInstance>()

defineProps({
  modelValue: {
    type: Object,
    default: () => { }
  },
  size: {
    type: String,
    default: () => 'default'
  },
  labelWidth: {
    type: [String, Number],
    default() {
      return '100px'
    }
  }
})

const emits = defineEmits(['search', 'reset'])

// 搜索/重置
const search = function () {
  emits('search')
}
const resetForm = function (formEl: FormInstance | undefined) {
  if (!formEl) return
  formEl.resetFields()
  emits('reset')
  search()
}

</script>

<style lang="scss" scoped>
</style>
